package com.example.servlet;

import com.example.dao.NovelDao;
import com.example.domain.Novel;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;
@WebServlet("/NovelMainServlet")
public class NovelMainServlet extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        request.setCharacterEncoding("utf-8");
        NovelDao novelDao = new NovelDao();
        List<Novel> novelList = novelDao.getIndexCount();
        if(novelList.size()==0){
            request.setAttribute("msg","获取小说失败!");
            request.getRequestDispatcher("index.jsp").forward(request,response);
        }
        HttpSession session = request.getSession();
        session.setAttribute("novelList",novelList);
        request.setAttribute("msg","用户登录成功!");
        request.getRequestDispatcher("index.jsp").forward(request,response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
        doGet(request,response);
    }
}
